<html>

<!--

Unix-like Sandbox in Windows Installer
Copyright (C) 2008 Ildar Shaimordanov

-->

<head>
<HTA:APPLICATION ID="oHTA"
	APPLICATIONNAME="SANDBOXWIN"
	BORDER="dialog"
	BORDERSTYLE="normal"
	CAPTION="yes"
	CONTEXTMENU="yes"
	ICON=""
	INNERBORDER="no"
	MAXIMIZEBUTTON="no"
	MINIMIZEBUTTON="yes"
	NAVIGABLE="no"
	SCROLL="no"
	SCROLLFLAT="no"
	SELECTION="no"
	SHOWINTASKBAR="yes"
	SINGLEINSTANCE="yes"
	SYSMENU="yes"
	VERSION="1.0"
	WINDOWSTATE="normal" />

<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Unix-like Sandbox in Windows Installer</title>
<style type="text/css">

*	{
	font-family: Verdana, Helvetica, Tahoma, 'Courier New', sans-serif;
	font-size: 0.97em;
}

body	{
	background-color: #CCCCCC;
	margin: 0;
	padding: 0;
	text-align: left;
}

#body	{
	padding: 0 10px;
}

#statusBar	{
	border: 1px inset #ccc;
	bottom: 0;
	position: absolute;
	width: 100%;
}

#statusBarCell	{
	background-color: #000099;
	color: #fff;
	height: 100%;
	width: 0;
}

#title	{
	padding: 15px 0 0 0;
	margin: 0;
}

a	{
	color: #0000ff;
	text-decoration: none;
}

form	{
	margin: 0;
}

fieldset	{
	margin: 10px 0;
}

table	{
	width: 100%;
}

.column_left	{
	text-align: right;
	vertical-align: top;
	width: 40%;
}

#SANDBOX_PATH	{
	width: 90%;
}

select	{
	font-family: Verdana, Helvetica, Tahoma, 'Courier New', sans-serif;
	width: 100%;
}

.button	{
	width: 100px;
}

pre.rc	{
	display: none;
}

</style>
<script language="javascript" src="js/win32/FileSystem.js"></script>
<script type="text/javascript" language="javascript">

// System dependent handlers
var fso = new ActiveXObject('Scripting.FileSystemObject');
var wsh = new ActiveXObject('WScript.Shell');
var env = wsh.Environment("PROCESS");

// Drive types
var DT_UNKNOWN		= 0;
var DT_REMOVABLE	= 1;
var DT_FIXED		= 2;
var DT_NETWORK		= 3;
var DT_CDROM		= 4;
var DT_RAMDISK		= 5;

// File attributes
var FA_READONLY		= 1;
var FA_HIDDEN		= 2;
var FA_SYSTEM		= 4;
var FA_DIRECTORY	= 16;
var FA_ARCHIVE		= 32;

</script>
<script type="text/javascript" language="javascript">

var sandbox = new (function()
{

	var self = this;

	var folders = [
		"bin",
		"etc",
		"home",
		"lib",
		"opt",
		"tmp",
		"usr",
		"var"];

	var name = "Sandbox";
	var installer = "";
	var uninstaller = "";

	/**
	 * Returns the sandbox folders
	 *
	 * @param	void
	 * @result	Array
	 * @access	public
	 */
	self.getFolders = function()
	{
		return folders;
	};

	/**
	 * Returns the full pathname of the content installer
	 *
	 * @param	void
	 * @result	String
	 * @access	public
	 */
	self.getContentInstaller = function()
	{
		return installer;
	};

	/**
	 * Returns the full pathname of the content uninstaller
	 *
	 * @param	void
	 * @result	String
	 * @access	public
	 */
	self.getContentUninstaller = function()
	{
		return uninstaller;
	};

	/**
	 * Returns the name of the sandbox
	 *
	 * @param	void
	 * @result	String
	 * @access	public
	 */
	self.getProjectName = function()
	{
		return name;
	};

	/**
	 * Launches the content installer.
	 * It should return TRUE if the uninstaller have to be removed during uninstalling
	 *
	 * @param	String	The full path to the sandbox
	 * @result	Boolean
	 * @access	public
	 */
	self.launchContentInstaller = function(sandbox_path)
	{
		var result = wsh.Run(self.getContentInstaller() + " " + sandbox_path, 1, true);

		return false;
	};

	/**
	 * Sets the content installer
	 *
	 * @param	String	The full pathname of the content installer
	 * @result	void
	 * @access	public
	 */
	self.setContentInstaller = function(value)
	{
		installer = value;
	};

	/**
	 * Sets the content uninstaller
	 *
	 * @param	String	The full pathname of the content uninstaller
	 * @result	void
	 * @access	public
	 */
	self.setContentUninstaller = function(value)
	{
		uninstaller = value;
	};

	/**
	 * Sets the sandbox name
	 *
	 * @param	String	The name of the sandbox
	 * @result	void
	 * @access	public
	 */
	self.setProjectName = function(value)
	{
		name = value;
	};

})();

</script>
<script type="text/javascript" language="javascript" src="Sandbox.js"></script>
<script type="text/javascript" language="javascript">

// Setters

function setDefaultPath()
{
	document.getElementById("SANDBOX_PATH").value = "C:\\" + sandbox.getProjectName();
};

function setDefaultDisk()
{
	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

	var c, d, e, list = "";

	for (var i = 0; i < chars.length; i++) {
		c = chars.charAt(i);

		// Looking for free drives
		try {
			d = fso.GetDrive(c);
			// Skip specific disks:
			// 3 - Network Disk
			// 4 - CD-ROM
			// 5 - RAM Disk
			if ( d.DriveType == DT_NETWORK || d.DriveType == DT_CDROM || d.DriveType == DT_RAMDISK ) {
				continue;
			}
			// Skip existing drives
			if ( d.IsReady ) {
				continue;
			}
		} catch (e) {
		}

		// Skip persistent disks already mapped in the registry
		if ( createSandboxPersist(c + ":") !== null ) {
			continue;
		}

		list += c;
	}

	if ( list == arguments.callee.list ) {
		return;
	}

	arguments.callee.list = list;

	var sandbox_disk = document.getElementById("SANDBOX_DISK");

	sandbox_disk.options.length = 0;
	for (var i = 0; i < list.length; i++) {
		c = list.charAt(i) + ":";
		sandbox_disk.options[i] = new Option(c, c);
	}

	// Set default disk "S:" or the last disk from the list
	sandbox_disk.options.selectedIndex = arguments.callee.list.search(/S/);
	if ( sandbox_disk.options.selectedIndex < 0 ) {
		sandbox_disk.options.selectedIndex = sandbox_disk.options.length - 1;
	}
};

setDefaultDisk.list = "";

function setDefaultPersist()
{
	// Prevent unsupported Windows 95/98/Me
	document.getElementById("persist_disk").disabled = env("OS") != "Windows_NT";
	document.getElementById("persist_disk").checked = env("OS") == "Windows_NT";
};

function setIcons(checked)
{
	var icons_allusers = document.getElementById("icons_allusers");

	// Bypass Windows 95/98/Me
	if ( env("OS") != "Windows_NT" ) {
		icons_allusers.disabled = true;
		icons_allusers.checked = false;
		icons_allusers.style.visibility = icons_allusers.nextSibling.style.visibility = "hidden";
		return;
	}

	icons_allusers.disabled = ! (
		document.getElementById("icons_desktop").checked || 
		document.getElementById("icons_startmenu").checked || 
		document.getElementById("icons_startup").checked );
};

// Installers

function isSandboxPath(spec)
{
	var e;

	// The folder for a sandbox should be read-only
	try {
		var f = fso.GetFolder(spec);
		if ( ! (f.Attributes & FA_READONLY) ) {
			return false;
		}
	} catch (e) {
		return false;
	}

	var fc = new Enumerator(f.SubFolders);

	var result = [];
	for ( ; ! fc.atEnd(); fc.moveNext()) {
		var folder = fc.item();
		// Skip hidden and system folders
		if ( folder.Attributes & FA_HIDDEN || folder.Attributes & FA_SYSTEM ) {
			continue;
		}
		result[result.length] = folder.Name;
	}

	var folders = sandbox.getFolders();

	// At least the number of subfolders should be greater or equals
	if ( result.length < folders.length ) {
		return false;
	}

	// Should contain the same standard subfolders like the sandbox
	var foldersReg = new RegExp("\\b(?:" + folders.join("|") + ")\\b", "g");
	result = result.sort().join(":").match(foldersReg);
	if ( ! result || result.length != folders.length ) {
		return false;
	}

	// Should contain the control file ...
	try {
		var controlFile = fso.GetFile(spec + "\\." + sandbox.getProjectName());
	} catch (e) {
		return false;
	}

	// ... that should be hidden, archive and read-only
	return !! (controlFile.Attributes & FA_HIDDEN && controlFile.Attributes & FA_READONLY && controlFile.Attributes & FA_ARCHIVE);
};

function modifyExecuteButton()
{
	var path = document.getElementById("SANDBOX_PATH").value;
	document.getElementById("execute").disabled = ! setDefaultDisk.list.length || path == "" || isSandboxPath(path);
};

function alarm(err, msg)
{
	alert((msg ? msg + "\n" : "") + "\nError Code: " + (err.number & 0xFFFF) + "\nError Message: " + err.description);
};

function createSandboxFolder(path, overwrite)
{
	var e, f;

	try {
		arguments.callee.list.unshift(path);

		if ( ! fso.FolderExists(path) ) {
			f = fso.CreateFolder(path);
		} else {
			if ( overwrite && ! confirm("\"" + path + "\" already exists. Continue?") ) {
				return false;
			}
			f = fso.GetFolder(path);
		}

		f.Attributes |= FA_READONLY;

		return true;
	} catch(e) {
		alarm(e, "Folder: " + path);

		throw new Error("Sandbox Error");
		return false;
	}
};

createSandboxFolder.list = [];

function createSandboxFile(path, container, attr, replacer)
{
	var e, f, t;

	try {
		arguments.callee.list.push(path);

		f = fso.CreateTextFile(path, true);
		if ( container ) {
			t = document.getElementById(container).innerText;
			if ( replacer ) {
				t = replacer(t);
			}
			f.Write(t);
		}
		f.Close();

		f = fso.GetFile(path);
		f.Attributes |= FA_READONLY | Number(attr);

		return true;
	} catch(e) {
		alarm(e, "File: " + path);

		throw new Error("Sandbox Error");
		return false;
	}
};

createSandboxFile.list = [];

function createSandboxShortcut(path, action, folder)
{
	var loc = wsh.SpecialFolders(folder);

	if ( ! loc ) {
		throw new Error("Can not create the shortcut at " + folder);
	}

	loc += "\\" + sandbox.getProjectName() + " " + action + ".lnk";

	createSandboxFile.list.push(loc);

	var lnk = wsh.CreateShortcut(loc);
	lnk.TargetPath		= path;
	lnk.Arguments		= action;
	lnk.WindowStyle		= 1;
//	lnk.HotKey		= "";
//	lnk.IconLocation	= "";
//	lnk.Description		= "";
//	lnk.WorkingDirectory	= "";
	lnk.Save();
};

function createSandboxPersist(disk, path)
{
	var key = "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\DOS Devices\\" + disk;

	if ( path ) {
		wsh.RegWrite(key, "\\??\\" + path, "REG_SZ");
		return;
	}

	try {
		return wsh.RegRead(key);
	} catch(e) {
		return null;
	}
};

function installSandboxContent(sandbox_path)
{
	var installer = sandbox.getContentInstaller();
	if ( ! installer || ! fso.FileExists(installer) ) {
		return;
	}

	return sandbox.launchContentInstaller(sandbox_path);
};

function installSandbox()
{
	var e, f, path, disk;

	path = document.getElementById("SANDBOX_PATH").value;

	disk = document.getElementById("SANDBOX_DISK").options;
	disk = disk[disk.selectedIndex].value;

	try {
		// Create the sandbox folder
		if ( ! createSandboxFolder(path, true) ) {
			return;
		}

		// Make a sandbox structure
		var folders = sandbox.getFolders();
		for (var i = 0; i < folders.length; i++) {
			createSandboxFolder(path + "\\" + folders[i]);
		}

		// Create the startup folders
		createSandboxFolder(path + "\\etc");
		createSandboxFolder(path + "\\etc\\rc.d");
		createSandboxFolder(path + "\\etc\\init.d");

		// Create the startup scripts
		createSandboxFile(path + "\\." + sandbox.getProjectName(), null, FA_HIDDEN + FA_READONLY + FA_ARCHIVE);
		createSandboxFile(path + "\\etc\\rc.bat", "rc_main", 0, function(t)
		{
			return t
				.replace(/@SANDBOX_PATH@/g, path)
				.replace(/@SANDBOX_DISK@/g, disk);
		});
		createSandboxFile(path + "\\etc\\init.d\\vdisk.bat", "rc_vdisk");
		createSandboxFile(path + "\\etc\\rc.d\\rc.start", "rc_d");
		createSandboxFile(path + "\\etc\\rc.d\\rc.stop", "rc_d");
		createSandboxFile(path + "\\etc\\rc.d\\rc.pause");

		// Run the external command to install the sandbox content
		var remove_uninstaller = installSandboxContent(path);

		// Make a persistent disk (if it needs)
		if ( document.getElementById("persist_disk").checked ) {
			createSandboxPersist(disk, path);
		}

		// Create shortcuts (if it needs)
		var allUsers = "";
		if ( document.getElementById("icons_allusers").checked ) {
			allUsers = "AllUsers";
		}

		if ( document.getElementById("icons_startup").checked ) {
			createSandboxShortcut(path + "\\etc\\rc.bat", "start", allUsers + "Startup");
		}
		if ( document.getElementById("icons_desktop").checked ) {
			createSandboxShortcut(path + "\\etc\\rc.bat", "start", allUsers + "Desktop");
			createSandboxShortcut(path + "\\etc\\rc.bat", "stop",  allUsers + "Desktop");
		}
		if ( document.getElementById("icons_startmenu").checked ) {
			createSandboxShortcut(path + "\\etc\\rc.bat", "start", allUsers + "StartMenu");
			createSandboxShortcut(path + "\\etc\\rc.bat", "stop",  allUsers + "StartMenu");
		}

		// Create uninstaller
		createSandboxFile(path + "\\etc\\uninstall_sandbox.bat", "rc_uninstall", 0, function(t)
		{
			var del_files = [];
			for (var i = 0; i < createSandboxFile.list.length; i++) {
				del_files[i] = "call :del_file \"" + createSandboxFile.list[i] + "\" 2>nul";
			}

			var del_dirs = [];
			for (var i = 0; i < createSandboxFolder.list.length; i++) {
				del_dirs[i] = "call :del_dir \"" + createSandboxFolder.list[i] + "\" 2>nul";
			}

			var uninstaller = sandbox.getContentUninstaller();
			if ( uninstaller && fso.FileExists(uninstaller) ) {
				t = t.replace(/@DEL_CONTENT@/, uninstaller);
				if ( remove_uninstaller ) {
					t = t.replace(/@REMOVE_UNINSTALLER@/, "remove");
				}
			}

			return t
				.replace(/@DEL_FILES@/, del_files.join("\n"))
				.replace(/@DEL_DIRS@/, del_dirs.join("\n"))
				.replace(/@SANDBOX_PATH@/g, path)
				.replace(/@SANDBOX_DISK@/g, disk);
		});
	} catch(e) {
		alarm(e, "The error caused the installation have not been performed properly.\nRemove the folder manually and try again.");
		return;
	}

	// Disable the "Execute" button
	document.getElementById("execute").disbled = true;
	document.getElementById("execute").style.visibility = "hidden";
};

</script>
<script type="text/javascript" language="javascript">

// Initialization routines

function setTimerInterval(time)
{
	if ( ! time || time <= 0 ) {
		clearInterval(arguments.callee.timerInterval);
		return;
	}

	arguments.callee.timerInterval = setInterval(function()
	{
		setDefaultDisk();
		setIcons();

		modifyExecuteButton();
	}, time);
};

function initForm()
{
	setDefaultPath();
	setDefaultPersist();
};

function closeWin()
{
	setTimerInterval();
	window.close();
};

function handleKeydown(e)
{
	var e = e || event;
	var target = e.target || e.srcElement;

	// F5
	if ( e.keyCode == 116 ) {
		return e.returnValue = false;
	}
};

function initWin()
{
	if (oHTA.applicationName !== "SANDBOXWIN") {
		window.close();
		return;
	}

/*
	// Specify the configurable parameters
	var matches;

	if ( matches = oHTA.commandLine.match(/project=(\w+)/) ) {
		sandbox.setProjectName(matches[1]);
	} else if (matches = oHTA.commandLine.match(/project="([^"]+)"/) ) {
		sandbox.setProjectName(matches[1]);
	}

	if ( matches = oHTA.commandLine.match(/install=(\w+)/) ) {
		sandbox.setContentInstaller(matches[1]);
	} else if (matches = oHTA.commandLine.match(/install="([^"]+)"/) ) {
		sandbox.setContentInstaller(macthes[1]);
	}

	if ( matches = oHTA.commandLine.match(/uninstall=(\w+)/) ) {
		sandbox.setContentUninstaller(matches[1]);
	} else if (matches = oHTA.commandLine.match(/uninstall="([^"]+)"/) ) {
		sandbox.setContentUninstaller(macthes[1]);
	}
*/

	// sets window size
	with (window.screen) {
		var w = 500, h = 400;
		moveTo((width - w) / 2, (height - h) / 2);
		resizeTo(w, h);
	}

	setTimerInterval(100);
	initForm();
};

</script>
</head>

<body onload="initWin()" onkeydown="handleKeydown()">

<div id="body">

<h4 id="title">Unix-like Sandbox in Windows Installer</h4>
<div style="font-size: 9px;">Copyright &copy; 2008 by Ildar Shaimordanov</div>

<form onsubmit="return false;">

<fieldset>
<legend>General</legend>

<table>
<tr>
<td class="column_left">

<label for="SANDBOX_PATH" title="Specify the folder where the sandbox will be created">Folder for the sandbox</label>

</td>
<td>

<input type="text" id="SANDBOX_PATH" />

<input type="button" value="..." onclick="var p = FileSystem.BrowseForFolder(0, this.title, 0, 17); if ( p ) document.getElementById('SANDBOX_PATH').value = p;" title="Browse folder for the sandbox" />

</td>
</tr>
<tr>
<td class="column_left">

<label for="SANDBOX_DISK" title="Select the drive to use as a shortcut to the sandbox">Name of the virtual disk</label>

</td>
<td>

<select id="SANDBOX_DISK">
<option></option>
</select>

</td>
</tr>
<tr>
<td class="column_left">&nbsp;</td>
<td>

<input type="checkbox" id="persist_disk" value="1" disabled="disabled" /><label for="persist_disk" title="Apply this for the persistent usage of virtual disk">Use the persistent virtual disk</label>

</td>
</tr>
</table>
</fieldset>

<fieldset title="Apply one of these to create icons at locations what you prefer">
<legend>Create icons</legend>
<table>
<tr>
<td class="column_left">&nbsp;</td>
<td>

<input type="checkbox" id="icons_desktop" value="Desktop" /><label for="icons_desktop">Desktop</label><br />
<input type="checkbox" id="icons_startmenu" value="StartMenu" /><label for="icons_startmenu">Start Menu</label><br />
<input type="checkbox" id="icons_startup" value="Startup" /><label for="icons_startup">Startup</label><br />

</td>
</tr>
<tr>
<td class="column_left">&nbsp;</td>
<td>

<input type="checkbox" id="icons_allusers" value="AllUsers" /><label for="icons_allusers">For all users</label>

</td>
</tr>
</table>
</fieldset>

<table>
</tr>
<tr>
<td class="column_left">&nbsp;</td>
<td>

<input type="button" class="button" id="execute" value="Continue" onclick="installSandbox()" disabled="disabled" />
<input type="button" class="button" id="close" value="Exit" onclick="closeWin()" />

</td>
</tr>
</table>
</form>

</div>
<div id="statusBar"><div id="statusBarCell"></div></div>

<pre id="rc_main" class="rc">@echo off


rem
rem Define the main variables
rem
set SANDBOX_PATH=@SANDBOX_PATH@
set SANDBOX_DISK=@SANDBOX_DISK@


if /i "%1" == "define" goto :EOF
if /i "%1" == "start"  goto normal_work
if /i "%1" == "stop"   goto normal_work


echo Usage:
echo     %~n0 start
echo     %~n0 stop
echo     %~n0 define
goto :EOF


rem
rem Main routine
rem
:normal_work

setlocal enabledelayedexpansion
setlocal enableextensions

set rc_etc=%SANDBOX_PATH%\etc\rc.d


rem
rem Looking for run-lists
rem
dir /a-d "%rc_etc%\rc.list" >nul 2>&1
if not errorlevel 1 (
	echo Run-list "%rc_etc%\rc.list" was found. Continue...
	for /f "usebackq" %%a in ( "%rc_etc%\rc.list" ) do (
		if /i "%1" == "start" set rc_list=!rc_list! %%a
		if /i "%1" == "stop"  set rc_list=%%a !rc_list!
	)
) else (
	dir /a-d "%rc_etc%\rc.%1" >nul 2>&1
	if errorlevel 1 (
		echo Run-list "%rc_etc%\rc.%1" is not exist. Exit^^!
		goto finish_work
	)
	echo Processing "%rc_etc%\rc.%1".
	for /f "usebackq" %%a in ( "%rc_etc%\rc.%1" ) do (
		set rc_list=!rc_list! %%a
	)
)


rem
rem Execute start/stop commands
rem
if "!rc_list!" == "" echo Empty run-list. Nothing to execute...

for %%a in ( !rc_list! ) do (
	echo %DATE% %TIME% Executing "%%a"...
	call "%SANDBOX_PATH%\etc\init.d\%%a.bat" %1
)


rem
rem Make a pause (if it needs) and finish
rem
:finish_work

if exist "%rc_etc%\rc.pause" (
	echo To prevent the appearance of this pause delete the file 
	echo "%rc_etc%\rc.pause".
	pause
)

set rc_list=
set rc_etc=
endlocal

</pre>
<pre id="rc_vdisk" class="rc">@echo off


rem
rem Executes to define the useful variables
rem
call "%~dp0\..\rc" define


if /i "%1" == "start" (
	echo Starting of the virtual disk %SANDBOX_DISK%
	subst %SANDBOX_DISK% "%SANDBOX_PATH%"
	goto :EOF
)


if /i "%1" == "stop" (
	echo Stopping of the virtual disk %SANDBOX_DISK%
	subst %SANDBOX_DISK% /D
	goto :EOF
)


if /i "%1" == "status" (
	subst
	goto :EOF
)


echo Usage:
echo     %~n0 start
echo     %~n0 stop
echo     %~n0 status

</pre>
<pre id="rc_d" class="rc">vdisk
</pre>

<pre id="rc_uninstall" class="rc">@echo off

if not defined uninstall_start (
	copy /b %0 %TEMP%\%~nx0 >nul
	set uninstall_start=1
	start "Uninstall of the sandbox" %TEMP%\%~nx0
	set uninstall_start=
	exit /b
)

set SANDBOX_PATH=@SANDBOX_PATH@
set SANDBOX_DISK=@SANDBOX_DISK@

setlocal enabledelayedexpansion
setlocal enableextensions

call :del_content "@DEL_CONTENT@" @REMOVE_UNINSTALLER@

call :del_subst
call :del_registry

@DEL_FILES@

@DEL_DIRS@

if exist "%SANDBOX_PATH%" echo "%SANDBOX_PATH%" is not empty and can not be removed.

call :end_script 2>nul

pause

endlocal
goto :EOF


:del_content
if %1 == "@DEL_CONTENT@" goto :EOF
if not exist %1 goto :EOF
echo Launch the sandbox uninstaller.
start "Sandbox Content Uninstaller" /wait %1
if /i "%2" == "remove" if exist %1 del %1
echo Sandbox content has been uninstalled.
goto :EOF


:del_subst
subst %SANDBOX_DISK% /d >nul
if errorlevel 1 goto :EOF
echo Virtual disk %SANDBOX_DISK% was unSUBSTed.
goto :EOF


:del_registry
set uninstall_reg="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices"
for /f "skip=4 tokens=1,2,*" %%a in ( 'reg query %uninstall_reg% /v "%SANDBOX_DISK%"' ) do (
	if /i "%%a" == "%SANDBOX_DISK%" if /i "%%c" == "\??\%SANDBOX_PATH%" (
		reg delete %uninstall_reg% /v %SANDBOX_DISK% /f >nul
		if errorlevel 1 goto :EOF
		echo Persistent disk "%SANDBOX_DISK%" was removed from the registry.
		goto :EOF
	)
)
goto :EOF


:del_file
if not exist %1 goto :EOF
set uninstall_attr=
dir %1 >nul 2>nul
if errorlevel 1 set uninstall_attr=/ah
del /f %uninstall_attr% %1
echo File %1 was deleted.
goto :EOF


:del_dir
if not exist %1 goto :EOF
for /f %%a in ( 'dir /b     %1' ) do goto :EOF
for /f %%a in ( 'dir /b /ah %1' ) do goto :EOF
for /f %%a in ( 'dir /b /as %1' ) do goto :EOF
rd /s /q %1
echo Dir %1 was removed.
goto :EOF


:end_script
for /f "delims==" %%a in ( 'set uninstall_' ) do set %%a=
set SANDBOX_DISK=
set SANDBOX_PATH=
goto :EOF

</pre>

</body>
</html>

